package ldkxingzhe.ldkxingzhedemo.menu;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.internal.view.menu.MenuBuilder;
import android.support.v7.widget.ActionMenuPresenter;
import android.support.v7.widget.ActionMenuView;
import android.util.Log;
import android.view.MenuItem;

import ldkxingzhe.ldkxingzhedemo.R;


/**
 * Created by ke on 15-9-2.
 */
public class ActionMenuViewActivity extends AppCompatActivity{
    private final String TAG = ActionMenuViewActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_action_menu_view);
        ActionMenuView actionMenuView = (ActionMenuView)findViewById(R.id.action_menu_view);
        MenuBuilder builder = new MenuBuilder(this);
        builder.setCallback(new MenuBuilder.Callback() {
            @Override
            public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
                Log.d(TAG,"onMenuItemSelected called");
                switch (item.getItemId()){
                    case R.id.item2:
                        Log.d(TAG,"item2 was clicked");
                        break;
                    case R.id.item3:
                        Log.d(TAG,"item3 was clicked");
                        break;
                    default:
                        break;
                }
                return false;
            }

            @Override
            public void onMenuModeChange(MenuBuilder menu) {
                Log.d(TAG,"onMenuModeChanged called");
            }
        });

        ActionMenuPresenter actionMenuPresenter = new ActionMenuPresenter(this);
        actionMenuPresenter.setReserveOverflow(true);
        actionMenuPresenter.setWidthLimit(getResources().getDisplayMetrics().widthPixels, true);
        actionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
        getMenuInflater().inflate(R.menu.drawerlayout_demo,builder);
        builder.addMenuPresenter(actionMenuPresenter,this);
        actionMenuView.setPresenter(actionMenuPresenter);
        actionMenuPresenter.updateMenuView(true);
    }
}
